﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RemoteTestRunner.UnitTesting;

namespace RemoteTestRunner.RTRDiagnosisTests
{
    /// <summary>
    ///   Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class DataDrivenSample
    {
        private static MultiAssertTestClassHelper _testClassHelper;

        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public static void MyClassInitialize(TestContext testContext)
        {
            _testClassHelper = new MultiAssertTestClassHelper("DataDrivenSample", testContext);
        }

        //
        // Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup]
        public static void MyClassCleanup()
        {
            _testClassHelper.Dispose();
        }

        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion

        /// <summary>
        ///   Gets or sets the test context which provides
        ///   information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        [TestMethod]
        [DeploymentItem("RTRDiagnosisTests\\testdata.xls")]
        [DataSource("DataDrivenSampleSource")]
        public void TestMethod1()
        {
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))
            {
                var input1 = 0;

                functionHelper
                    .AddInput("InputColumn", ref input1)
                    .AddInput("InputColumn2", TestContext.DataRow["InputColumn2"])
                    .AddInput("InputColumn3");

                var actualSum = input1 + Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                var actualDifference = input1 - Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                var actualDivision = Convert.ToDouble(input1) / Convert.ToDouble(TestContext.DataRow["InputColumn2"]);

                functionHelper
                    .AreEqual(actualSum, "Sum test int", "OutputColumn1")
                    .AreEqual<double>(actualSum, "Sum test double", "OutputColumn1")
                    .AreEqual(actualDifference, "Difference test", "OutputColumn2")
                    .AreEqual(actualDifference, "Difference test", "OutputColumn4")
                    .AreEqual(TestContext.DataRow["OutputColumn3"], actualDivision, "Division test",
                              "OutputColumn3")
                    .AreEqual((int)(double)TestContext.DataRow["OutputColumn1"], actualSum, "Sum test",
                              "OutputColumn1")
                    .AreEqual((int)(double)TestContext.DataRow["OutputColumn2"], actualDifference,
                              "Difference test", "OutputColumn2")
                    .AreEqual((double)TestContext.DataRow["OutputColumn3"], actualDivision, "Division test",
                              "OutputColumn3");
            }
        }

        [TestMethod]
        [DeploymentItem("RTRDiagnosisTests\\testdata.xls")]
        [DataSource("DataDrivenSampleSource")]
        //[Ignore]
        public void TestMethod2()
        {
            using (var functionHelper = _testClassHelper.GetFunctionHelper(TestContext))
            {
                var input1 = 0;

                functionHelper
                    .AddInput("InputColumn", ref input1)
                    .AddInput("InputColumn2", TestContext.DataRow["InputColumn2"])
                    .AddInput("InputColumn3");

                var actualSum = input1 + Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                var actualDifference = input1 - Convert.ToInt32(TestContext.DataRow["InputColumn2"]);
                var actualDivision = Convert.ToDouble(input1) / Convert.ToDouble(TestContext.DataRow["InputColumn2"]);

                functionHelper
                    .AreEqual(actualSum, "Sum test int", "OutputColumn1")
                    .AreEqual<double>(actualSum, "Sum test double", "OutputColumn1")
                    .AreEqual(actualDifference, "Difference test", "OutputColumn2")
                    .AreEqual(actualDifference, "Difference test", "OutputColumn4")
                    .AreEqual(TestContext.DataRow["OutputColumn3"], actualDivision, "Division test",
                              "OutputColumn3")
                    .AreEqual((int)(double)TestContext.DataRow["OutputColumn1"], actualSum, "Sum test",
                              "OutputColumn1")
                    .AreEqual((int)(double)TestContext.DataRow["OutputColumn2"], actualDifference,
                              "Difference test", "OutputColumn2")
                    .AreEqual((double)TestContext.DataRow["OutputColumn3"], actualDivision, "Division test",
                              "OutputColumn3");
            }
        }
    }
}